package edu.java.lectures.lec13.hash;

public class Person {

    // -- Instance Variables ---------------------------------------------------

    private String name;
    private int age;
    private String egn;

    // -- Constructors ---------------------------------------------------------

    public Person(String name, int age) {
	this.name = name;
	this.age = age;
    }

    // --- Getters and Setters -------------------------------------------------

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public int getAge() {
	return age;
    }

    public void setAge(int age) {
	this.age = age;
    }

    // -- Methods --------------------------------------------------------------

    @Override
    public boolean equals(Object obj) {
	// return toString().equals(obj); // EASY BUT NOT RELIABLE
	if (this == obj) {
	    return true;
	}
	if ((obj instanceof Person)) {
	    Person otherPerson = (Person) obj;
	    return getEgn().equals(otherPerson.getEgn());
	}
	return false;
    }

    @Override
    public int hashCode() {
	// return super.hashCode(); // TO BE OVERRIDEN
	// return toString().hashCode(); // EASY BUT NOT RELIABLE
	return getEgn().hashCode();
    }

    public String getEgn() {
	return egn;
    }

    @Override
    public String toString() {
	// return super.toString();
	return "[" + name + ", " + age + "]";
    }
}
